<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>分享</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #big {
            position: absolute;
            height: 200px;
            width: 200px;
            background-color: red;
            top: 200px;
            left: -200px;
            /*transition: 2s;*/
        }

        /*sass*/
        #big #small {
            position: absolute;
            height: 50px;
            width: 50px;
            background-color: #009933;
            left: 200px;
            top: 75px;
            text-align: center;
            line-height: 50px;
        }
    </style>
</head>
<body>
<div id="big">
    <div id="small">
        分享
    </div>
</div>
</body>
<script>
    var big = document.getElementById("big");
    var timer = null;
    var time = 10;

    big.onmouseover = function () {  //数值变化  多久完成
        clearInterval(timer);
        timer = setInterval(function () {
            var speed = (0-big.offsetLeft)/time;
            speed = speed>=0 ? Math.ceil(speed):Math.floor(speed);
            big.style.left = big.offsetLeft+speed+"px";
            if (big.offsetLeft == 0){
                clearInterval(timer);
            }
        }, 100);
    }
    big.onmouseout = function () {
        clearInterval(timer);
        timer = setInterval(function () {
            var speed = (-200-big.offsetLeft)/time;
            speed = speed>=0 ? Math.ceil(speed):Math.floor(speed);
            big.style.left = big.offsetLeft+speed+"px";
            if (big.offsetLeft == -200){
                clearInterval(timer);
            }
        }, 100);
    }
</script>
</html>